/*
 * $Id: ShemLogger.java,v 1.2 2009/06/25 15:54:22 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.processor.shemjob;

import java.io.File;
import java.io.PrintWriter;

import com.ge.healthcare.autosc.common.ASCLogger;
import com.ge.healthcare.autosc.common.exceptions.BasicException;
import com.ge.healthcare.autosc.common.util.ApplicationInfo;
import com.ge.healthcare.autosc.common.util.PropertyConstants;
import com.ge.healthcare.autosc.common.util.TimeFormatStandard;
import com.ge.healthcare.autosc.common.util.dataItem.ASCTextFileDataItem;
import com.ge.healthcare.autosc.common.util.dataItem.IASCTextDataItem;
/**
 * This is a simple helper class to report any Shem issues to interested party.
 * @author 212042946
 *
 */
public class ShemLogger {

	public static final String SHEM_TEAM = 
		ApplicationInfo.getInstance().getProperty(PropertyConstants.SHEM_TEAM, "shemteam");
	
	/**
	 * Place messages to the recipients queue so that the messages will
	 * be picked up and be notified to the recipients. 
	 * @param message	Message content for the recipients
	 * @param recipients	recipients name/identifier
	 * @param systemId	System ID
	 * @param task	ActTask
	 */
	public static void warn(String message, 
							String recipients,
							String systemId,
							String task) {
	        String lineToAppend = null;
        File queueDir = null;
        StringBuffer buffer = new StringBuffer();
        buffer.append( "Time: " );
        buffer.append( TimeFormatStandard.getNowMillis() );
        buffer.append( "  Site: " );
        buffer.append( systemId );
        buffer.append( "  Task: " );
        buffer.append( task );
        buffer.append( "  Warning: " );
        buffer.append( message );
        lineToAppend = buffer.toString();
		try {
	        String ppadsRoot = ApplicationInfo.getInstance().getProperty(PropertyConstants.PPADS_ROOT_PROPERTY, "ascpdata3/data2/ppads");
	        queueDir = new File( ppadsRoot, "queue/email" );
	        IASCTextDataItem dataItem = new ASCTextFileDataItem( queueDir, recipients );
	        PrintWriter outWriter = dataItem.openForWriting( true );
	        outWriter.println( lineToAppend );
	        outWriter.close();
		} catch (BasicException be) {
			// do nothing
		}
        ASCLogger.warn("Message: {" + lineToAppend + "}\nRecipient: {" + recipients + "}");
	}
}
